#ifndef QRSAGSDBMANAGERMAINWINDOW_H
#define QRSAGSDBMANAGERMAINWINDOW_H

#include <QMainWindow>
#include "winsock.h"
#include "qgspostgresconn.h"
#include "qgscolumntypethread.h"
#include "qgsproxyprogresstask.h"
#include "qgsprojectionselectionwidget.h"

namespace Ui {
class QRSAGSDBManagerMainWindow;
}

class QRSAGSDBManagerMainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit QRSAGSDBManagerMainWindow(QWidget *parent = nullptr, QString connName = QString());
    ~QRSAGSDBManagerMainWindow();

private:
    Ui::QRSAGSDBManagerMainWindow *ui;
    // Our thread for doing long running queries
    QgsGeomColumnTypeThread *mColumnTypeThread = nullptr;
    QgsProxyProgressTask *mColumnTypeTask = nullptr;
    QgsPostgresConn *mPostgresConn = nullptr;
    QSet<QString> mSchemaSet;//记录所有数据表架构
    QMap<QString, QStringList> mSchema2Tables;//建立数据表架构与表格之间的对应关系

    QString mDefaultPK = "id";
    QString mDefaultGeom = "geom";

    //初始化postgis的连接
    void initPostGISConnection();
    //连接postgis后，初始化从数据库中获取的架构schema和数据表
    void initImportDataToPostGIS();
    //连接postgis后，初始化从数据库中可以用来查询数据的架构schema和数据表
    void initQueryDataFromPostGIS();
    //根据选择的表格对象，更新查询界面中的对象列表
    void updateFieldListByTable(QString tableName);

public slots:
    void connectPostgreDatabase();
    void cb_geometryColumnsOnly_clicked();
    void testConnection();
    //! Updates state of the OK button depending of the filled fields
    void updateOkButtonState();
    void importSelectedLayerToPostgreSQL(bool );
    void expressionQuery(bool);
    void expressionClear(bool);
private:
    QString mOriginalConnName; //store initial name to delete entry in case of rename
};

#endif // QRSAGSDBMANAGERMAINWINDOW_H
